package com.ict.txmsv2.controller.studentinfo;


import com.ict.txmsv2.dto.StudentInfoQueryDto;
import com.ict.txmsv2.model.Certificates;
import com.ict.txmsv2.model.Patent;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.model.RespPageBean;
import com.ict.txmsv2.services.IPatentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 专利或软件著作权 前端控制器
 * </p>
 *
 * @author lht
 * @since 2021-04-24
 */
@RestController
@RequestMapping("/patent")
@Api(tags = "专利或软件著作权 前端控制器")
public class PatentController {

    @Resource
    private IPatentService patentService;

    @GetMapping
    @ApiOperation(value = "分页模糊查询专利或软件著作权信息")
    public RespPageBean getCertificates(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        StudentInfoQueryDto queryDto) {
        return patentService.list(page, size, queryDto);
    }

    @PostMapping
    @ApiOperation(value = "添加一个学生的专利或软件著作权")
    public RespBean addCertificate(@RequestBody Patent patent) {
        if (patentService.save(patent)) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败！");
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除一个专利或软件著作权")
    public RespBean delCertificate(@PathVariable(value = "id") Integer id) {
        if (patentService.removeById(id)) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败！");
    }

    @PutMapping
    @ApiOperation(value = "更新一个专利或软件著作权")
    public RespBean updateCertificate(@RequestBody Patent patent) {
        if (patentService.updateById(patent)) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败！");
    }

}
